package com.heima.search.controller.v1;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.search.dtos.UserSearchDto;
import com.heima.search.service.ApArticleSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/v1/article/search")
public class ApSearchController {

    @Autowired
    private ApArticleSearchService apArticleSearchService;

    /**
     * 基于es实现关键字搜索功能
     */
    @PostMapping("/search")
    public ResponseResult<List<ArticleDto>> searchArticle(@RequestBody @Valid UserSearchDto dto){
        List<ArticleDto> list = apArticleSearchService.searchArticle(dto);
        return ResponseResult.ok(list);
    }
}
